package com.itheima.webaitliasserver.controller;

import com.itheima.webaitliasserver.pojo.Clazz;
import com.itheima.webaitliasserver.pojo.PageResult;
import com.itheima.webaitliasserver.pojo.Result;
import com.itheima.webaitliasserver.request.ClassInfo;
import com.itheima.webaitliasserver.request.QueryClassListRequest;
import com.itheima.webaitliasserver.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: xiaoZhang
 * @Description:
 * @Author: Zhang
 * @CreateDate: 2025-09-05 15:29
 */
@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    /**
    * @Author: Zhang
    * @param:        
    * @createTime: 2025/9/5 15:34
    * @Description: 根据条件查询班级列表分页数据
    * @Return: 无
    */
    @GetMapping("/list")
    public Result queryClassList( QueryClassListRequest request){
        PageResult<Clazz> clazzPageResult = clazzService.queryClazzList(request);
        return  Result.success(clazzPageResult);
    }

    // 根据ID删除班级逻辑
    @DeleteMapping("/{id}")
    public Result deleteClazzById(@PathVariable Integer id){
        log.info("deleteClazzById:{}" , id);
        if(id == null){
            return Result.error("班级id不能为空");
        }
        clazzService.removeClassById(id);
        return Result.success("删除成功");
    }

    @PostMapping
    public Result addClazzInfo(@RequestBody ClassInfo classRequest){
        log.info("addClazzInfo:{}" , classRequest);
        clazzService.addClassInfo(classRequest);
        return  Result.success("添加成功");
    }
}
